/*
 * @Author: 小悟空 894251491@qq.com
 * @Date: 2023-12-02 09:32:48
 * @LastEditors: 小悟空 894251491@qq.com
 * @LastEditTime: 2023-12-12 10:14:43
 * @FilePath: \01\router\router.go
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package router

import (
	"01/controller"
	"github.com/gin-gonic/gin"
	"net/http"
)

// Router
//
//	@Description:
//	@return *gin.Engine
func Router() *gin.Engine {
	router := gin.Default()

	//err := router.SetTrustedProxies([]string{"127.0.0.1"})
	//if err != nil {
	//	return nil
	//}
	//路由分组
	user := router.Group("user")
	{

		//通过路由router调用控制器controller方法
		//get请求,接收参数,直接加:id
		user.GET("/GetUserInfo/:id", controller.GetUserInfo)
		//POST请求,接收参数,无需改动路由
		user.POST("/", controller.PostUserInfo)
		user.PUT("/", controller.PutUserInfo)

		//user.PUT("/", controller.UserController2{}.GetUserInfo)
		user.DELETE("/", func(context *gin.Context) {
			context.String(http.StatusOK, "user delete")
		})
	}
	//渲染数据到html
	router.LoadHTMLGlob("html/*")
	router.GET("/list", controller.GetList)

	//token学习验证
	token := router.Group("token")
	{
		token.GET("/", controller.Setting)
		token.POST("/", controller.Getting)
	}

	//curd学习
	goods := router.Group("goods")
	{
		goods.GET("/", controller.Index)
		goods.POST("/", controller.Insert)
		goods.PUT("/", controller.Update)
		goods.DELETE("/", controller.Delete)
	}

	return router
}
